#ifndef NETWORK_H
#define NETWORK_H

#include "common.h"

// Network Libraries
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>

// Struct to hold address and port number of sender
struct addressPort {
    //4-byte IP address
    unsigned int address;
    
    //2-byte port number
    unsigned short port;
};

// Configures host for call to bind
struct sockaddr * configureHost(unsigned short port);

// Fills the sockaddr struct with the given port and address
struct sockaddr * inputConnectionInfo(char * address, unsigned short port);

// Sends via UDP
void sendUDP(char * address, unsigned short port, int socketfd, unsigned char * msg, int msgLen);

// Receives via UDP
int receiveUDP(int socketfd, unsigned char * buffer, int bufferLen, struct sockaddr * senderSockAddr);

// Extracts address and port number from sockaddr struct
void getAddressPort (struct sockaddr * senderSockAddr, struct addressPort * senderInfo);

// Prints a message in hexadecimal
void printMessage(unsigned char * buffer, int byteCount);

// Converts a 4-byte IP address to its string representation
char * ipToString(unsigned int address);

#endif